package com.example.test_system.mapper;

import com.example.test_system.model.Judge;
import com.example.test_system.model.MultipleChoice;
import com.example.test_system.model.Question;
import com.example.test_system.model.SingleChoice;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface QuestionMapper {

    @Select("select * from judge order by rand() limit 10")
    public List<Judge> getJudge();

    @Select("select * from single_choice order by rand() limit 20")
    public List<SingleChoice> getSingleChoice();

    @Select("select * from multiple_choice order by rand() limit 4")
    public List<MultipleChoice> getMultipleChoice();

    @Insert("insert into judge (topic, answer) values(#{topic}, #{answer})")
    public void addJudge(Judge judge);

    @Insert("insert into single_choice (topic, items, answer) values(#{topic}, #{items}, #{answer})")
    public void addSingleChoice(SingleChoice singleChoice);

    @Insert("insert into multiple_choice (topic, items, answers) values(#{topic}, #{items}, #{answers})")
    public void addMultipleChoice(MultipleChoice multipleChoice);

    @Select("select * from judge limit #{page}, #{size}")
    public List<Judge> listJudge(int page, int size);

    @Select("select * from single_choice limit #{page}, #{size}")
    public List<SingleChoice> listSingleChoice(int page, int size);

    @Select("select * from multiple_choice limit #{page}, #{size}")
    public List<MultipleChoice> listMultipleChoice(int page, int size);

    @Delete("delete from judge where judge_id = #{id}")
    public void deleteJudgeById(int id);

    @Delete("delete from single_choice where sc_id = #{id}")
    public void deleteSingleChoiceById(int id);

    @Delete("delete from multiple_choice where mc_id = #{id}")
    public void deleteMultipleChoiceById(int id);
}
